package sz.szsmk.citizencard.ui.adapter;

import android.content.Context;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.model.network.bean.response.QueryMetroExitInfoRes;
import sz.szsmk.citizencard.ui.activity.SubwaySiteDetailActivity;

/**
 * Copyright (c)2019
 * author: zdh
 * created on: 2019/1/4 11:05
 * description:
 */
public class SubwayOpenAdapter extends RecyclerView.Adapter<SubwayOpenAdapter.SubwayOpenHolder> {
    private Context mContext;
    private List<QueryMetroExitInfoRes.MetroExtraInfoListBean.StandExtraListBean.StandExtraOfficeListBean> viewData;

    public SubwayOpenAdapter(SubwaySiteDetailActivity mContext) {
        this.mContext = mContext;
    }

    @Override
    public SubwayOpenHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.open_item, parent, false);
        return new SubwayOpenHolder(view);
    }

    @Override
    public void onBindViewHolder(SubwayOpenHolder holder, int position) {
        if (viewData != null) {
            holder.openTV.setText(viewData.get(position).getOffice());
            int office_type = viewData.get(position).getOffice_type();

            if (office_type == 1) {
                //其他
                holder.openIv.setImageResource(R.drawable.other_icon);
            }
            if (office_type == 2) {
                //学校
                holder.openIv.setImageResource(R.drawable.school_icon);
            }
            if (office_type == 3) {
//                景区
                holder.openIv.setImageResource(R.drawable.spot_icon);
            }
            if (office_type == 4) {
//                医院
                holder.openIv.setImageResource(R.drawable.hospit_icon);
            }
            if (office_type == 5) {
//                公交
                holder.openIv.setImageResource(R.drawable.bus_icon);
            }


        }
    }

    @Override
    public int getItemCount() {
        return null == viewData ? 0 : viewData.size();
    }

    public void setViewData(List<QueryMetroExitInfoRes.MetroExtraInfoListBean.StandExtraListBean.StandExtraOfficeListBean> viewData) {
        this.viewData = viewData;
    }

    public static class SubwayOpenHolder extends RecyclerView.ViewHolder {

        private final TextView openTV;
        private final ImageView openIv;

        public SubwayOpenHolder(View itemView) {
            super(itemView);
            openTV = (TextView) itemView.findViewById(R.id.subway_open_tv);
            openIv = (ImageView) itemView.findViewById(R.id.subway_open_iv);
        }
    }

}
